<?php

use yii\db\Migration;

/**
 * Class m220509_132517_request
 */
class m220509_132517_request extends Migration
{
    public $table = "request";
    public $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        $this->execute("drop table if exists $this->table;");
        $this->createTable($this->table, [
            'id' => $this->primaryKey(),
            'module' => $this->string(20)->notNull()->defaultValue("")->comment('module id'),
            'url' => $this->string(100)->notNull()->defaultValue("")->comment('pathinfo url'),
            'ip' => $this->string(20)->notNull()->comment("ipv4"),
            'created_at' => $this->dateTime()
        ], $tableOptions);
        $this->createIndex("url_index", $this->table, ["url"]);
        return true;
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        return true;
    }

    /*
    // Use up()/down() to run migration code without a transaction.
    public function up()
    {

    }

    public function down()
    {
        echo "m220509_132517_request cannot be reverted.\n";

        return false;
    }
    */
}
